package cn.ssdcc.dkserver.exception;

import cn.ssdcc.dkserver.entity.DkResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


//@RestControllerAdvice用于标识当前类为REST风格对应的异常处理器
@RestControllerAdvice
@Slf4j
public class ProjectExceptionAdvice {
    //@ExceptionHandler用于设置当前处理器类对应的异常类型
    @ExceptionHandler(SystemException.class)
    public DkResponse doSystemException(SystemException ex){
        log.error("SystemException",ex);
        return new DkResponse(ex.getCode(),ex.getMessage());
    }

    @ExceptionHandler(BusinessException.class)
    public DkResponse doBusinessException(BusinessException ex){
        log.error("BusinessException",ex);
        return new DkResponse(ex.getCode(),ex.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public DkResponse doOtherException(Exception ex){
        log.error("Exception",ex);
        return new DkResponse(12345,"系统繁忙，请稍后再试！");
    }
}